﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WindowsFormsApplication2.CLASS;
using WindowsFormsApplication2.All_FORMS.Lavlah_forms;

namespace WindowsFormsApplication2.FORMS
{
    public partial class frmXT : Form
    {
        public frmXT()
        {
            InitializeComponent();
        }
        public void FormatColumn(String colname, String caption, int index)
        {
            dataGridViewXT.Columns[colname].HeaderText = caption;
            dataGridViewXT.Columns[colname].DisplayIndex = index;
            dataGridViewXT.Columns[colname].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
        }
        public void FormatGrid()
        {
            dataGridViewXT.AllowUserToOrderColumns = true;
            dataGridViewXT.AllowUserToAddRows = false;
            dataGridViewXT.AllowUserToDeleteRows = false;
            dataGridViewXT.ReadOnly = true;
            dataGridViewXT.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
            dataGridViewXT.MultiSelect = true;

            FormatColumn("XTolologchId", "Худалдааны төлөөлөгчийн код", 0);
            FormatColumn("XTolologchName", "Худалдааны төлөөлөгчийн нэр", 1);
            FormatColumn("XTolologchUName", "Хэрэглэгчийн нэр", 2);
            FormatColumn("XTolologchAddress", "Худалдааны төлөөлөгчийн хаяг", 3);
            FormatColumn("XTolologchPhone", "Худалдааны төлөөлөгчийн утас", 4);
            dataGridViewXT.Columns["XTolologchPass"].Visible = false;
        }
        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnRegAdd_Click(object sender, EventArgs e)
        {
            frmRegXT frm = new frmRegXT();
            dataGridViewXT.DataSource = DBTools.selecQryTmp("Select *from XTolologch");
            frm.Show();
        }

        private void frmXT_Load(object sender, EventArgs e)
        {
            dataGridViewXT.DataSource = DBTools.selecQryTmp("Select *from XTolologch");
            FormatGrid();
        }

        private void btnRegDel_Click(object sender, EventArgs e)
        {
            int i = 0;
            XT cls = new XT();

            i = dataGridViewXT.CurrentRow.Index;
            DataRowView drv = dataGridViewXT.CurrentRow.DataBoundItem as DataRowView;

            if (drv != null)
            {
                string byXTrec = drv[0].ToString();

                XT.DelFunction(byXTrec);
                MessageBox.Show("Амжилттай устгалаа");
                dataGridViewXT.DataSource = DBTools.selecQryTmp("Select *from XTolologch");
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {

            dataGridViewXT.DataSource = DBTools.selecQryTmp("Select *from XTolologch");
        }

        private void btnRegEdit_Click(object sender, EventArgs e)
        {
            
        }

        private void button3_Click(object sender, EventArgs e)
        {
            int i = 0;
            

            i = dataGridViewXT.CurrentRow.Index;
            DataRowView drv = dataGridViewXT.CurrentRow.DataBoundItem as DataRowView;

            if (drv != null)
            {
                string byXTCode = drv[0].ToString();

                
                Form EA = new XT_Customer(byXTCode);
                
                EA.ShowDialog();

            }
        }

        private void dataGridViewXT_DoubleClick(object sender, EventArgs e)
        {
            int i = 0;
            XT cls1 = new XT();

            i = dataGridViewXT.CurrentRow.Index;
            DataRowView drv = dataGridViewXT.CurrentRow.DataBoundItem as DataRowView;

            if (drv != null)
            {
                string byXTCode = drv[0].ToString();

                cls1 = XT.getbyRec(byXTCode);
                Form EA = new frmRegXT(cls1);
                EA.ShowDialog();

                dataGridViewXT.DataSource = DBTools.selecQryTmp("Select *from XTolologch");
            }
        }

    }
}
